<html>
<head>
    <?php
    session_start();
    //使用session保持登录状态
    $conn = new mysqli("localhost", "root", "123456", "htmlkeshe");
    $conn->query("set names utf8");
    //使用md5加密密码 在验证时也进行加密后比较
    $sql = "select * from user where name='" . $_POST["name"] . "' and password='" . MD5($_POST["password"]) . "'";
    $result = $conn->query($sql) or die($conn->error());
    //die函数输出一条信息并退出当前脚本
    ?>
    <meta charset="UTF-8">
    <title>登入中喵～</title>
    <style>
        @import "resource/css/logoutCss.css";
    </style>
</head>
<body>
<?php
if(mysqli_num_rows($result)>0){
    $info=mysqli_fetch_assoc($result);
    //将所有信息写入session中方便读取
if ($info['warning'] >5){
    ?>
    <script>
        alert("该账号已经被封禁，请联系管理员");
        window.location.href="index.php";
    </script>
<?php
die();
}
$_SESSION['name']=$info['name'];
//echo ($_SESSION['username']);
$_SESSION['email']=$info['email'];
$_SESSION['phone']=$info['phone'];
$_SESSION['time']=$info['time'];
$_SESSION['head']=$info['head'];
$_SESSION['id']=$info['id'];
$_SESSION['admin']=$info['admin'];
$_SESSION["nrOfNews"]=$info['nrOfNews'];
$_SESSION["warning"]=$info["warning"];
?>
    <div class="left">
        <p>
            <?php
            setcookie(session_name(),session_id(),time()+3600,"/");
            echo ("欢迎");
            echo ($info["name"]."<br>");
            ?>
        </p>
    </div>
    <div class="cat">
        <img src="./resource/img/cat.png">
    </div>
    <div class="right">
        <?php
        header('Refresh: 2; url=index.php');
        echo "<a href='index.php'>正在跳转到主界面,若长时间未响应,则点击此处</a>";
        ?>
    </div>
<?php
}
else{
?>
    <div class="left">
        <p>
            <?php
            $info="用户名或密码错误，请重新输入";
            echo ($info);
            ?>
        </p>
    </div>
    <div class="cat">
        <img src="./resource/img/cat.png">
    </div>
    <div class="right">
        <?php
        header('Refresh: 2; url=index.php');
        echo "<a href='index.php'>正在跳转到主界面,若长时间未响应,则点击此处</a>";
        ?>
    </div>
    <?php
}
mysqli_close($conn);
?>
</body>
</html>



